﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dukou.Search
{
    public abstract class AbstractSearchResultItem : ISearchResultItem
    {
        private object m_id;

        public T Id<T>()
        {
            if (this.m_id == null)
            {
                return default(T);
            }
            if (this.m_id.GetType() == typeof(T))
            {
                return (T)this.m_id;
            }

            return default(T);
        }

        public ISearchResultItem Id<T>(T id)
        {
            this.m_id = id;

            return this;
        }

        /// <summary>
        /// 获取 底层对象
        /// </summary>
        public abstract object UnderlayerObject { get; }

        /// <summary>
        /// 获取 条目的字段名称集合<br/>
        /// IEnumerable&lt;string&gt;
        /// </summary>
        public abstract IEnumerable<string> FieldNames { get; }

        /// <summary>
        /// 获取值
        /// </summary>
        public object this[string fieldName]
        {
            get
            {
                return GetValue(fieldName);
            }
        }

        /// <summary>
        /// 获取值
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public abstract object GetValue(string fieldName);
    }
}
